import requests

from common.log_util import init_logger

logger = init_logger()

class EmployeeApi(object):

    @classmethod
    def add_emp(cls, headers, body):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        logger.debug(f"URL：{url}")
        logger.debug(f"headers：{headers}")
        logger.debug(f"body: {body}")
        resp = requests.post(url=url, headers=headers, json=body)
        logger.debug(f"response: {resp.json()}")
        return resp

    @classmethod
    def query_emp(cls, user_id, headers):
        url = "http://ihrm-test.itheima.net/api/sys/user" + "/" + user_id
        return requests.get(url=url, headers=headers)

    @classmethod
    def modify_emp(cls, user_id, headers, body):
        url = "http://ihrm-test.itheima.net/api/sys/user" + "/" + user_id
        return requests.put(url=url, headers=headers, json=body)

    @classmethod
    def del_emp(cls, user_id, headers):
        url = "http://ihrm-test.itheima.net/api/sys/user" + "/" + user_id
        return requests.delete(url=url, headers=headers)
